package 集合.map集合;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/*
    使用HashMap添加3个员工对象，要求键值：员工ID；值：对象
    并遍历显示工资>1800的员工
 */
public class 练习题 {
    public static void main(String[] args) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put(1,new Person("小溪", 1000));
        map.put(2,new Person("小楠", 3000));
        map.put(3,new Person("小呗", 500));
        map.put(4,new Person("小栋", 6000));

        Set<Object> keySet = map.keySet();
        for (Object o : keySet) {
            Person person = (Person)map.get(o);
            if(person.getSar() > 1800){
                System.out.println(map.get(o));
            }
        }
        Iterator<Object> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            Object key =  iterator.next();
            Person o = (Person)map.get(key);
            if(o.getSar() > 1800){
                System.out.println(map.get(key));
            }
        }

        Set<Map.Entry<Object, Object>> entrySet = map.entrySet();
        for (Map.Entry<Object, Object> objectObjectEntry : entrySet) {
            Person value = (Person)objectObjectEntry.getValue();
            if(value.getSar() > 1800){
                System.out.println(value);
            }

        }
    }
}

class Person{
    private String name;
    private double sar;

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sar=" + sar +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSar() {
        return sar;
    }

    public void setSar(double sar) {
        this.sar = sar;
    }

    public Person(String name, double sar) {
        this.name = name;
        this.sar = sar;
    }
}